#ifndef ECOCICTY_INVOICE_H
#define ECOCICTY_INVOICE_H

#include "InvoiceItem.h"
#include "Customer.h"
#include <QDate>
#include <vector>

namespace ecocity
{

class Invoice
{

public:

    enum STATE
    {
        OPEN        = 0,
        ARCHIVED    = 1
    };

    Invoice( const QDate& date,
             const Customer& customer );

    bool add_item( const InvoiceItem& item );

    bool remove_item( const QString& item_name,
                      int item_quantity,
                      float item_weight );

    void set_state( STATE );

    int id( ) const;

    STATE state( ) const;

    const QDate& date( ) const;

    Customer customer( ) const;

    const std::vector< InvoiceItem >& items( ) const;

    // Include profit
    float total_cost( ) const;
    float taxes_cost( ) const;
    float cost_without_taxes( ) const;

    float profit( ) const;

private:

    void update_costs( );

private:

    int m_id;

    QDate m_date;

    //Composition: If invoice dies, customer dies
    Customer m_customer;
    //Aggregation: If invoice dies, customer still exists
    //const Customer* m_customer;

    // Composition: If Invoice dies, InvoiceItems died
    std::vector< InvoiceItem > m_items;

    float m_cost_without_taxes;
    float m_total_taxes;
    float m_total_profit;
    float m_total_cost;

    STATE m_state;
};

}      // namespace ecocity

#endif // ECOCICTY_INVOICE_H
